//
//  RWNetworkCache.h
//  RWNetwork
//
//  Created by Ray on 2024/4/25.
//  Copyright © 2024 81SK. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "RWNetworkDefines.h"

#if __has_include(<RWCache/RWYCache.h>)
#import <RWCache/RWYCache.h>
#else
#import "RWYCache.h"
#endif

NS_ASSUME_NONNULL_BEGIN

@interface RWNetworkCache : NSObject

/// 缓存存储策略 (默认不存储)
@property (nonatomic, assign) RWNetCacheWritePolicy writePolicy;

/// 缓存读取策略 (默认不读取)
@property (nonatomic, assign) RWNetCacheReadPolicy readPolicy;

/// 缓存有效时长 (单位：秒，默认不限制)
@property (nonatomic, assign) NSTimeInterval cacheSeconds;

/// 缓存 key 额外的部分，默认是 app 版本号
@property (nonatomic, copy) NSString *cacheVersion;

/// 磁盘缓存对象
@property (nonatomic, class, readonly) RWDiskCache *diskCache;

/// 内存缓存对象
@property (nonatomic, class, readonly) RWMemoryCache *memoryCache;

/** 根据默认的缓存 key 自定义缓存 key */
@property (nonatomic, copy, nullable) NSString *(^customCacheKeyBlock)(NSString *defaultCacheKey);

/// 存数据
/// @param object 数据对象
/// @param key key 标识
- (void)setObject:(nullable id<NSCoding>)object forKey:(id)key;

/// 取数据
/// @param key key 标识
/// @param block 回调 (主线程)
- (void)objectForKey:(NSString *)key withBlock:(void(^)(NSString *key, id<NSCoding> _Nullable object))block;

/// 获取磁盘缓存大小
/// @return 缓存大小(单位 M)
+ (NSInteger)getDiskCacheSize;

/// 清除磁盘缓存
+ (void)removeDiskCache;

/// 清除内存缓存
+ (void)removeMemeryCache;

@end

NS_ASSUME_NONNULL_END
